#pragma once
#include "Position.h"
#include <queue>

using namespace std;

class Player
{
	friend class Game;

public:
	int playerID;
	Position pos;

	Player(){}
	~Player(){}

	Player(int xPos, int yPos, int id)
	{
		pos.id = id;
		pos.pos[0] = xPos;
		pos.pos[1] = yPos;
		playerID = id;
	}

	void updatePosition(deque<char> &keyPressQueue, deque<Position> &posQueue, Player &p)
	{
		bool isNewKey = false;
		char c = NULL;
		if (keyPressQueue.size() != 0)
		{
			c  = keyPressQueue.back();
			keyPressQueue.pop_back();
		}
		if(((p.playerID == 1 && c == 'w') || (p.playerID == 2 && c == 'i')) && ( p.pos.pos[1] > 1))
		{
			p.pos.pos[1]--;
			isNewKey = true;
		}
		else if(((p.playerID == 1 && c == 'a') || (p.playerID == 2 && c == 'j')) && ( p.pos.pos[0] > 1))
		{
			p.pos.pos[0]--;
			isNewKey = true;
		}
		else if(((p.playerID == 1 && c == 's') || (p.playerID == 2 && c == 'k')) && ( p.pos.pos[1] < 22))
		{
			p.pos.pos[1]++;
			isNewKey = true;
		}
		else if(((p.playerID == 1 && c == 'd') || (p.playerID == 2 && c == 'l')) && ( p.pos.pos[1] < 39))
		{
			p.pos.pos[0]++;
			isNewKey = true;
		}
		if(isNewKey)
			posQueue.push_front(p.pos);
	}
};
		
